package com.xs.project.email;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        new Test().test();
    }
    public void test() throws InterruptedException {
        Map<String, String> map = new HashMap<>();
        CountDownLatch countDownLatch = new CountDownLatch(20);

        ExecutorService taskExecutor = Executors.newFixedThreadPool(10); // 假设我们使用一个固定大小的线程池

        for (int i = 0; i < 20; i++) {
            final int finalI = i;
            taskExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    map.put(String.valueOf(finalI), String.valueOf(finalI));
                    countDownLatch.countDown();
                }
            });
        }

        boolean await = countDownLatch.await(2, TimeUnit.SECONDS);
        System.out.println(await);

        Map<Object, Object> map1 = new HashMap<>(map);
        System.out.println(map.size());

        System.out.println(map.size());
        System.out.println(map1.size());

        taskExecutor.shutdown();
    }
}
